package com.qiaoyanqing.ximalaya.discovermodule.discover_adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.qiaoyanqing.ximalaya.R;
import com.qiaoyanqing.ximalaya.discovermodule.discover_entity.Broadcast_Categories;

import java.util.List;

/**
 * Created by Administrator on 2016/12/5.
 */

public class Broadcast_GridViewAdapter extends BaseAdapter {
    private List<Broadcast_Categories> list;
    private Context context;
    private LayoutInflater inflater;
    private int count;

    public Broadcast_GridViewAdapter(List<Broadcast_Categories> list, Context context, int count) {
        this.list = list;
        this.context = context;
        this.count = count;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if (count == 8) {
            return 8;
        } else {
            return list.size();
        }
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = inflater.inflate(R.layout.broadcast_gridview_item, viewGroup, false);
            holder = new ViewHolder();
            holder.gridview_tv = (TextView) view.findViewById(R.id.gridView_tv);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.gridview_tv.setText(list.get(i).getName());
        if (count==8){
            if (i == 7) {
                holder.gridview_tv.setText("");
               holder.gridview_tv.setBackgroundResource(R.drawable.ic_triangle_down);
            }
        }
        if (i == list.size()-1) {
            holder.gridview_tv.setText("");
            holder.gridview_tv.setBackgroundResource(R.drawable.ic_triangle_up);
        }
        return view;
    }

    static class ViewHolder {
        TextView gridview_tv;
    }
}
